	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="<?=$this->baseUrl?>/public/js/ext3.2/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="<?=$this->baseUrl?>/public/css/icons.css"> 
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/ext3.2/ext-base.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/ext3.2/ext-all.js"></script>
<title>数据统计</title>
</head>
<script type='text/javascript'>
Ext.BLANK_IMAGE_URL = '<?=$this->baseUrl?>/public/images/default/s.gif';
Ext.chart.Chart.CHART_URL='<?=$this->baseUrl?>/public/js/ext3.2/charts.swf';
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());	
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';	
var cp = new Ext.state.CookieProvider();
Ext.onReady(function(){
					 
					 
var module="";
var ExtId=Ext.id();
var baseUrl="<?=$this->baseUrl?>";
var time="<?=date('y-m-d h:i:s')?>";
var linktype_combo_store=new Ext.data.JsonStore({
																	  url:baseUrl+'/link/serverlinktype',
																	  root:'results',
																	  fields:['linktype_id','linktype_name']
																	  });
linktype_combo_store.load();
var linktype_combo=new Ext.form.ComboBox({
										 id:'link_type',
										 fieldLabel:'链接类型',
										 width:120,
										 store:linktype_combo_store,										
        								displayField:'linktype_name',
        								valueField :'linktype_id',
										hiddenName:"linktype_id",
        								typeAhead:true,
        								mode:'local',
        								triggerAction:'all',
                                        editable:false,  
        								selectOnFocus:true,
                                        emptyText:"请选择",
                                        listeners:{
                                        select:function(){
											reloadStore();
											}
										}
										 }); 
var column_linktype_combo=new Ext.form.ComboBox({
										 id:'column_link_type',
										 fieldLabel:'链接类型',
										 width:120,
										 store:linktype_combo_store,										
        								displayField:'linktype_name',
        								valueField :'linktype_id',
										hiddenName:"linktype_id",
        								typeAhead:true,
        								mode:'local',
        								triggerAction:'all',
                                        editable:false,  
        								selectOnFocus:true,
                                        emptyText:"请选择",
                                        listeners:{
                                        select:function(){
											column_reloadstore();
											}
										}
										 }); 
var seo_store=new Ext.data.JsonStore({
									fields:['u_id','username'],
									totalProperty:'total',
									root:'results',
									url:baseUrl+'/link/userdata'
									});				 
seo_store.load();
var seo_combo=new Ext.form.ComboBox({			
										id:'seo_id',
										fieldLabel:'链接类型',
										width:100,
										store:seo_store,										
        								displayField:'username',
        								valueField :'u_id',
										hiddenName:"u_id",
        								typeAhead:true,
        								mode:'local',
        								triggerAction:'all',
                                        editable:false,  
        								selectOnFocus:true,
                                        emptyText:"请选择",
										listeners:{
											select:function(){
												reloadStore();
												}
											}
										 }); 
var column_seo_combo=new Ext.form.ComboBox({			
										id:'column_seo_id',
										fieldLabel:'链接类型',
										width:100,
										store:seo_store,										
        								displayField:'username',
        								valueField :'u_id',
										hiddenName:"u_id",
        								typeAhead:true,
        								mode:'local',
        								triggerAction:'all',
                                        editable:false,  
        								selectOnFocus:true,
                                        emptyText:"请选择",
										listeners:{
											select:column_reloadstore
											}
										 }); 
var store = new Ext.data.JsonStore({
        fields: ['username', 'count'],
		totalProperty: 'total',
		root:'results',
        url:baseUrl+'/link/chartdata/'
    });
store.load();   
var pie_store = new Ext.data.JsonStore({
        fields: ['username', 'count'],
		totalProperty: 'total',
		root:'results',
        url:baseUrl+'/link/chartdata/'
    });
pie_store.load();   
var line_store=new Ext.data.JsonStore({
									  fields:['day','count','username'],
									  totalProperty:'total',
									  root:'results',
									  url:baseUrl+'/link/chartdata/type/line'									  
									  });
line_store.load();
var column_store=new Ext.data.JsonStore({
									  fields:['month','count','username'],
									  totalProperty:'total',
									  root:'results',
									  url:baseUrl+'/link/chartdata/type/column'									  
									  });
column_store.load();
var piechart=new Ext.Panel({		
        title: '链接发布分布图',
		collapsible:true,
        items: {
            store: pie_store,			
            xtype: 'piechart',
            dataField: 'count',
            categoryField: 'username',				
			tipRenderer:function(chart,record){
			return record.data.username+"共发布"+record.data.count+"条链接";
			},
            //extra styles get applied to the chart defaults
            extraStyle:
            {
                legend:
                {
                    display: 'right',
                    padding: 5,
                    font:
                    {
                        family: 'yahei',
                        size: 13
                    }
                }
            }
        },
		tbar:['选择时间段：从',{
		  								xtype:'datefield',
		  								format:'Y-m-d',
          								id:'pie_start_date',
          								value:'<?=date('Y-m-d',time()-86400*30)?>',
          								maxValue:'<?=date('Y-m-d')?>',
										listeners:{
											change:pie_reloadstore
											}
		  								},'至',
		  								{
										xtype:'datefield',
										format:'Y-m-d',
										id:'pie_end_date',
										value:'<?=date('Y-m-d',time()+86400)?>'	,
										listeners:{
											change:pie_reloadstore
											}
		  								},{
											text:'查询',
											iconCls:'icn-search',
											handler:pie_reloadstore
											}]
    });
	
var columnChart=new Ext.Panel({
	title:'SEO趋势图(按月)',
	collapsible:true,
	items:[{
			store:column_store,
			xtype:'columnchart',
			xField:'month',
			yAxis:new Ext.chart.NumericAxis({
											title:'链接数量'	
											}),
			xAxis:new Ext.chart.CategoryAxis({
											 title:'月份'
											 }),
			categoryField: 'username',
			tipRenderer:function(chart,record){
			if(Ext.getCmp('column_seo_id').getValue()){
				var user=Ext.getCmp('column_seo_id').getRawValue();
				return user+"在"+record.data.month+"月份,共发布"+record.data.count+"条链接";
				}
			return "在"+record.data.month+"月份,共发布"+record.data.count+"条链接";
			},
			series:[{
					type:'column',
					displayName:'数量',
					yField:'count',
					style:{
						mode:'stretch',
						color:0x99bbc5}
					}],
			  extraStyle:
            {
                legend:
                {
                    display: 'right',
                    padding: 5,
                    font:
                    {
                        family: 'yahei',
                        size: 13
                    }
                }
            }			
		}],
	tbar:["SEO：",column_seo_combo,'-','从',{
		  								xtype:'datefield',
		  								format:'Y-m-d',
          								id:'column_start_date',
          								value:'<?=date('Y-m-d',time()-86400*30)?>',
          								maxValue:'<?=date('Y-m-d')?>',
										listeners:{
											change:column_reloadstore
											}
		  								},'至',
		  								{
										xtype:'datefield',
										format:'Y-m-d',
										id:'column_end_date',
										value:'<?=date('Y-m-d',time()+86400)?>'	,
										listeners:{
											change:column_reloadstore
											}
		  								},'-','链接类型',column_linktype_combo]
	});
	
	var linechart=new Ext.Panel({
								title:'SEO趋势图(按日统计)',
								colspan:2,
								width:1300,
								collapsible:true,
								items:[{
									   xtype:'linechart',
									   store:line_store,
									   xField:'day',
									   yField:'count',
									   yAxis:new Ext.chart.NumericAxis({
											title:'链接数量'	
										}),
										xAxis:new Ext.chart.CategoryAxis({
											title:'日期'
										}),
										tipRenderer:function(chart,record){
											if(Ext.getCmp('seo_id').getValue()){
												var user=Ext.getCmp('seo_id').getRawValue();
												return user+"发布"+record.data.count+"条";
											}
											else{
												return "共发布"+record.data.count+"条";
												}
										},
									   }],
										tbar:["SEO：",seo_combo,'-','从',{
		  								xtype:'datefield',
		  								format:'Y-m-d',
          								id:'start_date',
          								value:'<?=date('Y-m-d',time()-86400*30)?>',
          								maxValue:'<?=date('Y-m-d')?>',
										minValue:'<?=date('Y-m-d',time()-86400*365)?>',
										listeners:{
											change:reloadStore
											}
		  								},'至',
		  								{
										xtype:'datefield',
										format:'Y-m-d',
										id:'end_date',
										value:'<?=date('Y-m-d',time()+86400)?>'	,
										listeners:{
											change:reloadStore
											}
		  								},'-','链接类型',linktype_combo]
										});
	
new Ext.Panel({
				  autoHeight:true,
				  autoWidht:true,
				  title:'图表演示',
				  layout:'table',
				  frame:true,
				  layoutConfig: {columns:2},
				  defaults: {width:660, height: 320,style:'padding:5px 20px 5px 5px'},				  
				  renderTo:Ext.getBody(),
				  items:[piechart,columnChart,{
					width:1320,
                    colspan:2,layout:'fit',items:[linechart]}]
				  });


function reloadStore(){
	var seo_id=Ext.getCmp('seo_id').getValue();
	var start_time=Ext.getCmp('start_date').getValue().format('Y-m-d H:i:s');
	var end_time=Ext.getCmp('end_date').getValue().format('Y-m-d H:i:s');
	var link_type=Ext.getCmp('link_type').getValue();
	line_store.baseParams.where="link_input_date between '"+start_time+"' and '"+end_time+"'";
	if(link_type){
		line_store.baseParams.where+=" and 	link_linktype_id='"+link_type+"'";
		}
	if(seo_id){
		line_store.baseParams.where+=" and link_user_id='"+seo_id+"'";
	}
	line_store.reload();
	}
	
function pie_reloadstore(){
	var start_time=Ext.getCmp('pie_start_date').getValue().format('Y-m-d H:i:s');
	var end_time=Ext.getCmp('pie_end_date').getValue().format('Y-m-d H:i:s');
	pie_store.baseParams.where="link_input_date between '"+start_time+"' and '"+end_time+"'";
	pie_store.reload();
	}

function column_reloadstore(){
	var seo_id=Ext.getCmp('column_seo_id').getValue();
	var start_time=Ext.getCmp('column_start_date').getValue().format('Y-m-d H:i:s');
	var end_time=Ext.getCmp('column_end_date').getValue().format('Y-m-d H:i:s');
	var link_type=Ext.getCmp('column_link_type').getValue();
	column_store.baseParams.where="link_input_date between '"+start_time+"' and '"+end_time+"'";
	if(link_type){
		column_store.baseParams.where+=" and 	link_linktype_id='"+link_type+"'";
		}
	if(seo_id){
		column_store.baseParams.where+=" and link_user_id='"+seo_id+"'";
	}
	column_store.reload();
	}
});
</script>
</head>

<body>
<?
// print_r(json_decode($json));
?>

</body>
</html>